home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / plane / d2_dic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  1.6 KB  |  69 lines

  1. #include "LEDA/d2_dictionary.h"
  2.  
  3.  
  4.  
  5. main()
  6. {
  7.   double k1, l1, r1;
  8.   string k2("....."), l2, r2;
  9.   int i, j;
  10.   dic2_item it;
  11.  
  12.   d2_dictionary<double,string,int> t;
  13.  
  14.   int MAX = read_int("number of elements = ");
  15.   dic2_item* items = new dic2_item[MAX];
  16.  
  17.   for (i=0; i<MAX; i++) {
  18.     k1 = 1+random(0,9899)/100.0;
  19.     for( j=0; j<k2.length(); j++ )
  20.       k2[j] = random(97,122);
  21.     items[i] = t.insert( k1, k2, i );
  22.   }
  23.  
  24. // t.print();
  25.  
  26.   forall_dic2_items( it, t )
  27.     cout << t.inf(it) << ": (" << t.key1(it) << "," 
  28.          << t.key2(it) << ")" << endl;
  29.  
  30.   newline;
  31.   cout << "Enter 0 to stop queries!";
  32.   newline;
  33.  
  34.   while( (l1=read_real(" left(1) = ")) && 
  35.          (r1=read_real("right(1) = ")) ) {
  36.     l2 = read_string(" left(2) = "); r2 = read_string("right(2) = ");
  37.  
  38.     list<dic2_item> res = t.range_search( l1, r1, l2, r2 );
  39.     forall( it, res )
  40.       cout << t.inf(it) << ": (" << t.key1(it) << "," 
  41.                        << t.key2(it) << ")" << endl;
  42.   }
  43.   newline;
  44.  
  45.   cout << "min_key1: " << t.inf(t.min_key1()) << " (" 
  46.        << t.key1(t.min_key1()) << "," << t.key2(t.min_key1()) 
  47.        << ")" << endl;
  48.   cout << "min_key2: " << t.inf(t.min_key2()) << " (" 
  49.        << t.key1(t.min_key2()) << "," << t.key2(t.min_key2()) 
  50.        << ")" << endl;
  51.  
  52.   cout << "max_key1: " << t.inf(t.max_key1()) << " (" 
  53.        << t.key1(t.max_key1()) << "," << t.key2(t.max_key1()) 
  54.        << ")" << endl;
  55.   cout << "max_key2: " << t.inf(t.max_key2()) << " (" 
  56.        << t.key1(t.max_key2()) << "," << t.key2(t.max_key2()) 
  57.        << ")" << endl;
  58.  
  59.   print_statistics();
  60.  
  61.   for (i = 0; i < MAX; i++) {
  62.     t.del( t.key1(items[i]), t.key2(items[i]) );
  63.   }
  64.  
  65.   delete items;
  66.  
  67.   return 0;
  68. }
  69.